package com.firefly.service.repository.cms;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.firefly.dao.dao.cms.mapper.TypeMapper;
import com.firefly.dao.dao.cms.po.TypePo;
import com.firefly.dao.dao.cms.service.TypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @description: 分类
 * @author: lzg(萤火科技 ： 854378082 @ qq.com)
 * @date: 2022/12/13
 **/
@Repository
public class TypeRepository {
    private final TypeService typesService;
    private final TypeMapper typesMapper;
    @Autowired
    public TypeRepository(TypeService typesService, TypeMapper typesMapper){
        this.typesService = typesService;
        this.typesMapper = typesMapper;
    }

    public Boolean create(TypePo entity){
        return typesService.save(entity);
    }
    public Boolean updateName(TypePo entity){
        return typesService.updateById(entity);
    }
    public Boolean sort(int id,int sort) {
        UpdateWrapper<TypePo> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id",id);
        updateWrapper.set("sort",sort);
        return typesService.update(updateWrapper);
    }
    public List<Integer> getIds(Integer id){
        return typesMapper.getAllChildId(id);
    }
    public boolean removeId(List<Integer> ids){
        return typesService.removeByIds(ids);
    }
}
